class ShoppingCartController < ApplicationController
 layout"common"
  def index
    @cart=find_cart
  end
  
  def delete_from_cart
    if request.post?
      @cart=find_cart
       if @cart.delete_product_at(params[:id])
         flash[:notice]="该商品不存在！"
       end
       redirect_to(:action=>"index")      
    else
      redirect_to(:action=>"index")
    end  
  end
  
  def empty_cart
       session[:cart]=nil
       redirect_to(:action=>"index")
  end

private  
  def find_cart
      session[:cart] ||=Cart.new
  end
end
